package com.bwie.system.service.impl;

import com.bwie.common.domain.request.LoginRequest;
import com.bwie.common.domain.response.UserInfo;
import com.bwie.common.exctption.BizException;
import com.bwie.system.mapper.SysUserMapper;
import com.bwie.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务处理层
 *
 * @author <a href="mailto:2891704036@qq.com">zhiyuheng</a>
 * @version 1.0
 * @description: 业务处理层
 * @date 2025/8/28 9:03
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 根据手机号和密码查询用户信息
     * @param loginRequest
     * @return
     */
    @Override
    public UserInfo findByPhoneAndPassword(LoginRequest loginRequest) {
        //手机号正则
        String phone = loginRequest.getPhone();
        if (!phone.matches("1[3-9]\\d{9}")){
            throw new BizException("手机号格式错误");
        }
        UserInfo userInfo = sysUserMapper.findByPhoneAndPassword(loginRequest);
        return userInfo;
    }
}
